﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IntelligentRouteAssist
{
    public class RouteGenerator
    {
        public static ZRoute GenerateRoute(List<RouteObj> source,ZTimeline startTime)
        {
            List<RouteMallObj> malls = source.OfType<RouteMallObj>().ToList();
            List<RouteNode> nodes = new List<RouteNode>();
            malls.ForEach(m =>
                {
                    List<RouteStoreObj> stores = source.Where(r =>
                        {
                            return r.mall.mall_id == m.mall_id;
                        }).Select(r => r.store).ToList();
                    RouteNode node = new RouteNode()
                    {
                        mall = m,
                        stores = stores
                    };
                    nodes.Add(node);
                });
            nodes = nodes.OrderByDescending(n => n.CalculateScore()).ToList();
            ZRoute route = new ZRoute()
            {
                nodes = nodes
            };
            route.ArrangeNodes(startTime);
            return route;
        }
    }
}
